package com.h2cloud.reflection.test;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @Package: com.h2cloud.reflection.test
 * @ClassName: Main
 * @Author: h2cloud
 * @CreateTime: 2022/11/20 8:55 下午
 * @Description:
 */
public class Main {
	public static void main(String[] args) throws Exception {
		Person p = new Person();
		p.setName("longkai");

		// 获取属性
		Field field = Person.class.getDeclaredField("name");
		field.setAccessible(true);
		String name = (String) field.get(p);
		System.out.println("name = " + name);

		// 执行方法-getName
		Method method = Person.class.getDeclaredMethod("getName");
		method.setAccessible(true);
		String returnVal = (String) method.invoke(p);
		System.out.println("returnVal = " + returnVal);

		// 执行方法-getNameUpper
		Method method2 = Person.class.getDeclaredMethod("getNameUpper");
		method2.setAccessible(true);
		String returnVal2 = (String) method2.invoke(p);
		System.out.println("returnVal2 = " + returnVal2);


		Object name1 = reflectUtil.getFieldValue(Person.class, p, "name");
		System.out.println("name1 = " + name1);

	}
}
